package com.zxy.ziems.server.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.domain.AgreementChannel;
import com.zxy.ziems.server.dto.AgreementChannelDto;
import com.zxy.ziems.server.dto.AgreementChannelQueryDto;
import com.zxy.ziems.server.service.AgreementChannelService;
import com.zxy.ziems.server.vo.AgreementChannelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName AgreementController
 * @Description
 * @Author 邓伟
 * @Date 2023/11/29 10:52
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/agreementChannel")
public class AgreementChannelController {

    @Autowired
    private AgreementChannelService agreementChannelService;

    @PostMapping("/addOrUpdate")
    public JsonResponse addOrUpdate (@RequestBody @Validated AgreementChannelDto agreementChannelDto) {
        agreementChannelService.addOrUpdate(agreementChannelDto);
        return JsonResponse.SUCCESS();
    }

    @GetMapping("/delete")
    public JsonResponse delete (@RequestParam(value = "channelId") String channelId) {
        agreementChannelService.delete(channelId);
        return JsonResponse.SUCCESS();
    }

    @PostMapping("/page/list")
    public JsonResponse<PageResult<AgreementChannelVo>> pageList (@RequestBody AgreementChannelQueryDto agreementChannelQueryDto) {
        PageResult<AgreementChannelVo> pageResult = agreementChannelService.pageList(agreementChannelQueryDto);
        return JsonResponse.SUCCESS(pageResult);
    }

    @GetMapping("/list")
    public JsonResponse<List<AgreementChannel>> list () {
        List<AgreementChannel> list = agreementChannelService.list();
        return JsonResponse.SUCCESS(list);
    }

    @GetMapping("/getDetail")
    public JsonResponse<AgreementChannelVo> detail (@RequestParam(value = "channelId") String channelId) {
        AgreementChannelVo agreementChannelVo = agreementChannelService.detail(channelId);
        return JsonResponse.SUCCESS(agreementChannelVo);
    }
}
